package ksic.lookdom;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import ksic.lookdom.service.LookdomService;
import ksic.lookdom.vo.Lookd_BizDetailVo;
import ksic.lookdom.vo.Lookd_BizmasterVo;
import ksic.lookdom.vo.Lookd_UserVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import spring.board.vo.LoginVo;

@Controller
public class LookdomController {
	@Autowired
	private LookdomService lookdomService;
	
	@RequestMapping("/testlogin.do")
	public void testLogin(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
	
	@RequestMapping("/testpic.do")
	public void testPic(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
	
	@RequestMapping("/testsignup.do")
	public void testSignup(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
	}
	
	@RequestMapping("/index.do")
	public void indexController(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		System.out.println("index");
	}
	
	/* 濡쒓렇�씤 �럹�씠吏� */
	@RequestMapping("/login.do")
	public void loginController(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		System.out.println("login page");
	}
	
	/* 濡쒓렇�씤 �슂泥� */
	@RequestMapping("/login2.do")
	public @ResponseBody Map<?, ?>/*@ResponseBody Map<?, ?>*/ login(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
		String id = (String) paramMap.get("id");
		String pw = (String) paramMap.get("pw");
		
		String pwChk = lookdomService.login(id);
		boolean isLogin = false;
		
		if(pwChk.equals(pw)) {
			isLogin = true;
		} else {
			isLogin = false;
		}
		
		model.put("isLogin", isLogin);
		
		return model;
	}
	
	@RequestMapping("/signUp.do")
	public void signUp(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
	}
	
	@RequestMapping("/signUp2.do")
	public ModelAndView signUpController(HttpServletRequest request) throws Throwable {
		
		String id = request.getParameter("id");
		//System.out.println(userVo.getId());
		System.out.println(id);
		
		lookdomService.signUpService(id);
		
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/signUp");
		return mv;
	}
	
	@RequestMapping("/signUp3.do")
	public ModelAndView signUp3(HttpServletRequest request) throws Throwable {
		
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		
		Lookd_UserVo userVo = new Lookd_UserVo();
		userVo.setId(id);
		userVo.setPw(pw);
		
		System.out.println(pw);
		
		lookdomService.sigbUpService(userVo);
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/signUp");
		
		return mav;
	}
	
	@RequestMapping("/biz.do")
	public void bizController(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		System.out.println("biz");
	}
	
	@RequestMapping("/goBiz.do")
	public ModelAndView goBiz(HttpServletRequest request) throws Throwable {
		String bizcd = request.getParameter("bizcd");
		String groupcd = request.getParameter("groupcd");
		String bizname = request.getParameter("bizname");
		String bizcont = request.getParameter("bizcont");
		String stdate = request.getParameter("stdate");
		String modate = request.getParameter("modate");
		
		Lookd_BizmasterVo bizMaster = new Lookd_BizmasterVo();
		bizMaster.setBizcd(bizcd);
		bizMaster.setGroupcd(groupcd);
		bizMaster.setBizname(bizname);
		bizMaster.setBizcont(bizcont);
		bizMaster.setStdate(stdate);
		bizMaster.setModate(modate);
		
		lookdomService.bizService(bizMaster);
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/biz");
		
		return mav;
	}
	
	@RequestMapping("/bizList.do")
	public void bizList(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		System.out.println("bizList");
		//String id = "ksic";
		//Lookd_UserVo userVo = lookdomService.loginServie(id);
	}
	
	/* JSON�쓣 �씠�슜 */
	@RequestMapping("/getBizList.do")
	public @ResponseBody Map<?, ?>/*@ResponseBody Map<?, ?>*/ getBizList(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
		List<Lookd_BizmasterVo> bizList = lookdomService.bizListService();
		model.put("bizList", bizList);
		
		return model;
	}
	
	
	/* JSON�쓣 �씠�슜 */
	@RequestMapping("/getBizDetail.do")
	public @ResponseBody Map<?, ?>/*@ResponseBody Map<?, ?>*/ getBizDetail(@RequestParam Map<String, Object> paramMap, ModelMap model) throws Throwable {
		
		String bizcd = (String) paramMap.get("bizcd");
		System.out.println(bizcd);
		Lookd_BizDetailVo bizDetail =  lookdomService.getBizDetailService(bizcd);
		System.out.println(bizDetail.getBizcd());
		model.put("bizDetail", bizDetail);
		
		return model;
	}
	
	
	
	
	
}
